package com.example.forum.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.forum.MyQuery;
import com.example.forum.entity.TAppuser;
import com.example.forum.entity.TBlock;
import com.example.forum.entity.TBlockarea;
import com.example.forum.mapper.TAppuserMapper;
import com.example.forum.mapper.TBlockMapper;
import com.example.forum.mapper.TBlockareaMapper;
import com.example.forum.service.ITBlockareaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author why
 * @since 2020-04-22
 */
@Service
public class TBlockareaServiceImpl extends ServiceImpl<TBlockareaMapper, TBlockarea> implements ITBlockareaService {

    @Autowired
    TBlockareaMapper blockareaMapper;

    @Autowired
    TAppuserMapper appuserMapper;

    @Autowired
    TBlockMapper blockMapper;




    @Override
    public List<TBlock> getBlockList(TAppuser appUser) {

        List<TBlock> tBlocks = blockMapper.getBlockList(appUser.getRegionid(),appUser.getStreetid(),appUser.getNeighborhoodcommitteeid());

        return tBlocks;

//        List<String> tBlockIds = blockareaMapper.selectList(
//                new MyQuery<TBlockarea>().select("blockid")
//                        .in("AreaId", appUser.getStreetid(),appUser.getRegionid(),appUser.getNeighborhoodcommitteeid()))
//                        .stream().map(TBlockarea::getBlockid).collect(Collectors.toList());
//        List<String> tBlockareasIds = blockareaMapper.selectList(
//                new MyQuery<TBlockarea>().select("id")
//                        .in("AreaId", appUser.getStreetid(),appUser.getRegionid(),appUser.getNeighborhoodcommitteeid()))
//                .stream().map(TBlockarea::getId).collect(Collectors.toList());
//        List<TBlock> tBlocks = blockMapper.selectList(new MyQuery<TBlock>().in("id", tBlockIds));
//        for (int i = 0; i < tBlocks.size(); i++) {
//            TBlock tBlock = tBlocks.get(i);
//            tBlock.setBlockAreaId(tBlockareasIds.get(i));
//        }
    }
}
